import React from "react";
import ComponentType from "../../Config/ComponentType";
import InputComp from "../../InputComp";
import ComboBox from "../../ComboBox";
import NumberInput from "../../NumberInput";
import SwitchComp from "../../SwitchComp";
import ObjectBox from "../../ObjectBox";
import DateComp from "../../DateComp";
import ObjectEnum from "../../ObjectEnum";
import NumberRange from "../../NumberInput/NumberRange";
// import AddrBookSelect from "../../AddrBookSelect";
// import AcctFactor from "../../AcctFactor";
// import FcFactor from "../../FcFactor";
// import EmbedSelector from "../../EmbedSelector";
// import AutoCompleteComp from "../../AutoCompleteComp";
// import FilterEditorComp from "../../FilterEditorComp";
// import CustEmbedSelector from "../../CustEmbedSelector";
// import ExpressionComp from "../../ExpressionComp";
// import TagFinder from "../../TagFinder";
// import TagEditor from "../../TagEditor";

const CompTypes = {
    [ComponentType.TEXT_INPUT]: InputComp,
    [ComponentType.TEXT_AREA]: {
        Comp: InputComp,
        props: {
            textarea: true
        }
    },
    [ComponentType.COMBO_BOX]: ComboBox,
    [ComponentType.NUMBER_INPUT]: NumberInput,
    [ComponentType.NUMBER_RANGE]: NumberRange,
    [ComponentType.CALENDAR]: DateComp,
    [ComponentType.CHECK_BOX]: SwitchComp,
    [ComponentType.FINDER]: ObjectBox,
    [ComponentType.OBJERCT_ENUM]: ObjectEnum,
    // [ComponentType.AUTO_COMPLETE]: AutoCompleteComp,
    // [ComponentType.TAG_FINDER]: TagFinder,
    // [ComponentType.TAG_EDITOR]: TagEditor,
    // [ComponentType.ADDR_INPUT]: AddrBookSelect,
    // [ComponentType.ACCT_FACTOR]: AcctFactor,
    // [ComponentType.FC_FACTOR]: FcFactor,
    // [ComponentType.EMBED_SELECTOR]: EmbedSelector,
    // [ComponentType.CUST_EMBED_SELECTOR]: CustEmbedSelector,
    // [ComponentType.FILTER_EDITOR]: FilterEditorComp,
    // [ComponentType.EXPRESSION]: ExpressionComp,
};

/**
 * 根据 type 获取基础组件（GeneralComp 除外）
 * @param type
 * @param props
 * @return {null|*}
 */
export const getSimpleComp = (type, props = {}) => {
    // console.log('getSimpleComp', type)
    const CompCls = CompTypes[type];
    let defaultProps = {};
    let Comp;

    if (CompCls && CompCls.Comp) {
        Comp = CompCls.Comp;
        defaultProps = props || {};
    } else {
        Comp = CompCls;
    }

    if (Comp) {
        return <Comp {...defaultProps} {...props} />;
    } else {
        return null;
    }

};
